﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NPlot;

namespace homeWork_1_12
{
  public partial class Form1 : Form
  {
    //ALL all = new ALL();
    SystemEquations all = new SystemEquations();
    public Form1()
    {
      InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
      double rightBorder = 10000.0;
      double J, k, F, m, n, g, b;
      J = Convert.ToDouble(textBox1.Text);
      k = Convert.ToDouble(textBox2.Text);
      F = Convert.ToDouble(textBox3.Text);
      m = Convert.ToDouble(textBox6.Text);
      n = Convert.ToDouble(textBox5.Text);
      g = Convert.ToDouble(textBox4.Text);
      b = Convert.ToDouble(textBox7.Text);

      double h, Eps, x0, omega0, phi0, derPhi0;
      int maxSteps;
      h = Convert.ToDouble(textBox10.Text);
      maxSteps = Convert.ToInt32(textBox9.Text);
      Eps = Convert.ToDouble(textBox8.Text);
      x0 = Convert.ToDouble(textBox14.Text);
      omega0 = Convert.ToDouble(textBox13.Text);
      phi0 = Convert.ToDouble(textBox12.Text);
      derPhi0 = Convert.ToDouble(textBox11.Text);

      //all.setMaxSteps(maxSteps);
      //all.setParams(J, k, F, m, n, b, g);
      //all.equation.createMainEqation(maxSteps, x0, omega0, Eps, rightBorder);
      //all.system.createMainEqation(maxSteps, x0, phi0, derPhi0, Eps, rightBorder);
      //all.equation.h = h;
      //all.system.h = h;
      //all.h = h;
      //all.step = 0;
      //all.doNSteps(maxSteps - 1);

      all.setParams(J, k, F, m, n, b, g);
      all.createMainEqation(maxSteps, h, x0, omega0, phi0, derPhi0, Eps);
      all.doNSteps(maxSteps);
    }

    private void button2_Click(object sender, EventArgs e)
    {
      plotSurface2D1.Clear();
      int start = Convert.ToInt32(textBox16.Text);
      int finish = Convert.ToInt32(textBox15.Text);
      double[] absciss = new double[finish - start];
      double[] ordinate = new double[finish - start];

      #region заполнение абсциссы и ординаты
      if (radioButton1.Checked)
      {
        for (int i = start; i < finish; i++)
        {
          //ordinate[i - start] = all.equation.v[i];
          //absciss[i - start] = all.equation.x[i];

          ordinate[i - start] = all.omega[i];
          absciss[i - start] = all.x[i];
        }
      }

      if (radioButton2.Checked)
      {
        for (int i = start; i < finish; i++)
        {
          //ordinate[i - start] = all.system.v[i];
          //absciss[i - start] = all.system.x[i];

          ordinate[i - start] = all.phi[i];
          absciss[i - start] = all.x[i];
        }
      }

      if (radioButton3.Checked)
      {
        for (int i = start; i < finish; i++)
        {
          //ordinate[i - start] = all.system.derV[i];
          //absciss[i - start] = all.system.x[i];

          ordinate[i - start] = all.derPhi[i];
          absciss[i - start] = all.x[i];
        }
      }

      if (radioButton4.Checked)
      {
        for (int i = start; i < finish; i++)
        {
          //ordinate[i - start] = all.system.derV[i];
          //absciss[i - start] = all.system.v[i];

          ordinate[i - start] = all.derPhi[i];
          absciss[i - start] = all.phi[i];
        }
      }
      #endregion

      // вывод графика на экран
      LinePlot lp2 = new LinePlot();
      lp2.OrdinateData = ordinate;
      lp2.AbscissaData = absciss;
      lp2.Pen = new Pen(Color.Red, 1.0f);
      plotSurface2D1.Add(lp2);
      this.plotSurface2D1.Refresh();

      // вывод начальной точки на экран
      //PointPlot p = new PointPlot();
      //p.AbscissaData = absciss[0];
      //p.OrdinateData = ordinate[0];
      //p.Marker = new Marker();
      //plotSurface2D1.Add(p);
      //this.plotSurface2D1.Refresh();

    }
  }
}
